﻿/*
 * Author: Georgi
 * Date: 19.03.2011
 */
using System;

namespace ProjectStorageLib
{
    /// <summary>
    /// A class that is going to be a root class for all other classes in the project.
    /// This class and its successors realise IDisposable interface for deterministic 
    /// memory and resource management
    /// </summary>
    [Serializable]
    public abstract class ClassRoot : IDisposable
    {
        /// <summary>
        /// A method to realize IDisposable interface
        /// </summary>
        public void Dispose()
        {
            //Call internal dispose method
            Dispose(true);

            //Disconnect from garbage collection finalize queue
            System.GC.SuppressFinalize(this);
        }

        /// <summary>
        /// A Destructor of the class
        /// </summary>
        ~ClassRoot()
        {
            //Call internal dispose method
            Dispose(false);
        }

        /// <summary>
        /// A method to be realized in successors for implementing 
        /// resourse and memory disposal.
        /// </summary>
        /// <param name="flag">flag marking if the Dispose is triggered by user or by system </param>
        protected abstract void Dispose(bool flag);
    }
}
